package com.lxq.LeetCode.search704;

public class Solution {
    public static void main(String[] args) {
        int[] nums = {1,11};
        int target = 1;
        System.out.println(search(nums, target));
    }

    public static int ss(int[] nums, int target, int p1, int p2) {
        if (p2 < p1) {
            return -1;
        }
        if (p2 == p1) {
            if (nums[p1] == target) {
                return p1;
            } else {
                return -1;
            }
        }
        int res = -1;
        int p = p1 + (p2 - p1) / 2;
        if (nums[p] == target) {
            return p;
        } else if (nums[p] > target) {
            p = p - 1;
            res = ss(nums, target, p1, p);
        } else {
            p = p + 1;
            res = ss(nums, target, p, p2);
        }
        return res;
    }

    public static int search(int[] nums, int target) {
        if (nums.length == 0) {
            return -1;
        }
        int res = -1;
        res = ss(nums, target, 0, nums.length - 1);
        return res;
    }
}
